home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 5.8 KB | 122 lines | [TEXT/GEOL] |
- Item forwarded by LAI1 to D4384
-
- Item 4741332 20-Jan-90 08:28
-
- From: LAI1 Lai, Edmund
-
- To: MACAPP.TECH$ MacApp Technical
-
- Sub: Persistent/virtual objects
-
- I think Greg Colvin's persistent object solution is more a solution to "virtual
- object": the total size of all objects are too big to fit into memory and not
- all are needed to be in memory at the same time. So only a header of the object
- is keep in memory and the rest is load as needed. I think the Card sample
- program does more or less the same thing.
-
- Other have pointed out some problems. Pointer to other object are not handled,
- it uses a lot of handles. Of course the object to lots of handle is that they
- still take up a lot of room. If you have a million objects and you calculate
- how much memory the dehydrated form alone would occupy, then scheme would not
- work. It works best when you have a small number of large objects (and there is
- no saving if there are many small objects).
-
- The problem need to be distinguished from persistent object because if we have
- view objects, we can put it away on to disk and get it back later functionally
- intact, then I think we have solved the persistent object problem, but still we
- have not solve the problem that there is a very big view with so many subviews
- that they cannot be fitted into memory. That is the issue of virtual objects.
-
- Larry Rosenstein's suggestion of using an index or ID to represent an object
- and load it on demand is a sound one and in fact is a better solution to the
- virtual object problem. Now suppose you have a million objects out there but
- there is still chance that the program will run in the 1M machine (how well
- that would run is another matter).
-
- One way to distinguish the key and a object is to use odd longint to be the
- key. Since a handle is never odd, you can store object pointer and index in the
- same place, in the begining it is the index. Before you access the field you do
- the call
-
- if Odd(longint(fOtherObject)) then
- fOtherObject := KeyToObject(longint(fOtherObject));
- fOtherObject.DoItsThing;
-
- This is not without its problem, if objects are virtual then they can be
- swapped out, so the fact it has been translated from index to handle is no
- guarantee.
-
- One solution to the problem is have a reference count and not to swap out until
- the reference count is zero;
-
- if Odd(longint(fOtherObject)) then
- begin
- fOtherObject := KeyToObject(longint(fOtherObject));
- with fOtherObject do fRefCount := fRefCount + 1;
- end;
- fOtherObject.DoItsThing;
-
- TMyObject.Free;
- begin
- with fOtherObject do fRefCount := fRefCount - 1;
- Inherited Free
- end;
-
- Or we can have a TList field fObjectsUsingMe so that when an object is purged,
- it would go through the list and reverting them to index, but there is a lot of
- bookkeeping to do.
-
- There may be the question, why do this everytime fOtherObject is referenced,
- why not do it in object init time once. The problem is that if you a million
- objects connected in a link list, when you tried to init the first object you
- would bring in a million objects. With the approach advocated above, you would
- not bring in a object unless you really needs it. Of course it can be a mixture
- of both approachs, you know you are going to need to refer to the field many
- times, you do it at object init time, if it is a million object link list, you
- do it when you really need the other object.
-
- Actually I think the cleanest approach is to always keep the index around, and
- translate to object when you use it, and there is a cache of recently used
- objects so that most of the time it is not necessary to go to the disk. So you
- have
-
- KeyToObject(fOtherObjectKey).DoItsThing;
-
- You may say that this is very inefficient. Obviously there are a lot more
- overhead compared to
-
- fOtherObject.DoItsThing;
-
- The question is that is this fast enough that the user would not care. I know
- at least one popular Mac program that use that approach and it does not seem to
- have a performance problem. I think people should try it out, if it is fast
- enough, why bother with other headaches.
-
- Now on a complete different topic, I keep hearing that all this discussion is
- not a solution to persistent object problem becasue it does not address
- persistence of methods as well as data. If I have a view, I can save it and get
- it later, full functional, that is persistent object for me. The methods of the
- view is available to me before I save it and it is available to me when I load
- the object back in, why do I need to do anything about the methods. If what it
- means is that if I create a new method, there is no way of storing it for me.
- Well for MACAPP, you can not even create a new method on run time, so why blame
- it on persistence. If what you mean is that in OOP, objects is data +
- behaviour. Therefore if you just save data, transfer it to another environment
- then you cannot use it because there is no behavior(methods). If it is a view,
- you transfer the view object to another environment, they should have the
- methods for views and display it. So it is not a problem. If it is some kind of
- TMyObject, so that the class and hence methods are not available over there.
- Again MACAPP would not even allow you to create the object over there so it is
- not a problem.
-
- Let us assume for a moment that all of these are indeed possible under MACAPP,
- then should we save methods as well as objects so that we can transfer behavior
- as well as data. Obviously that would be nice. But it would also be nice when I
- give you a MacWrite document, I give you a copy of MacWrite because without it
- you cannot read the document anyway, so data (documeent) is useless without
- behavior (application). While this is interesting in academic research, I am
- not sure how many developers want to support this. One day maybe object can
- have scripts attached to it like in HyperCard, but that is a completely
- different story.
-
-